home *** CD-ROM | disk | FTP | other *** search
- #include "Bilanz.h"
-
- void StatusMonth(long dir) /* show infos about month */
- { char s[15], i;
- for (i=1; i<=13; i++) {
- ScrollRaster(RP,0L,dir,100L,31L,124L,43L);
- ScrollRaster(RP,0L,dir,256L,31L,336L,43L);
- ScrollRaster(RP,0L,dir,432L,31L,512L,43L);
- Delay(1);
- }
- SetAPen(RP,1L);
- Print(Monthname[curmonth],100,40);
- ltos(monthexpend,s,10,8,' '); Print(s,256,40);
- SetAPen(RP,2L);
- ltos(monthincome,s,10,8,' '); Print(s,432,40);
- }
- void StatusYear(long dir) /* show infos of the year */
- { char s[15];
- int mon, i;
- if (dir) {
- for (i=1; i<=13; i++) {
- ScrollRaster(RP,0L,dir,96L,14L,128L,26L);
- ScrollRaster(RP,0L,dir,256L,14L,336L,26L);
- ScrollRaster(RP,0L,dir,432L,14L,512L,26L);
- ScrollRaster(RP,0L,dir,256L,31L,336L,43L);
- ScrollRaster(RP,0L,dir,432L,31L,512L,43L);
- Delay(1);
- }
- }
- if (!filter) {
- yearincome = year->income;
- yearexpend = year->expend;
- }
- else {
- struct Entry *entry;
- yearincome = yearexpend = 0;
- for (mon=1; mon<=12; mon++) {
- entry = year->month[mon].first;
- while (entry) {
- if (FilterCmp(entry->area)) {
- if (entry->costs > 0) yearincome += entry->costs;
- else yearexpend += labs(entry->costs);
- }
- entry = entry->next;
- }
- }
- }
- SetAPen(RP,1L);
- ltos(curyear,s,4,0,' '); Print(s,96,23);
- Print(Monthname[curmonth],100,40);
- ltos(yearexpend,s,10,8,' '); Print(s,256,23);
- ltos(monthexpend,s,10,8,' '); Print(s,256,40);
- SetAPen(RP,2L);
- ltos(yearincome,s,10,8,' '); Print(s,432,23);
- ltos(monthincome,s,10,8,' '); Print(s,432,40);
- }
-
- void Arrow(void) /* draws arrows if not all entries are shown */
- {
- int arrowup, arrowdown;
- if (!filter) {
- arrowup = (!count) ? 0 : 1;
- arrowdown = (count < number-MAXLINE) ? 1 : 0;
- }
- else {
- struct Entry *entry;
- int i, j;
- entry = year->month[curmonth].first;
- i = 0;
- while (entry && !FilterCmp(entry->area)) {
- entry = entry->next;
- i++;
- }
- arrowup = (i < count) ? 1 : 0;
- j = 0;
- while (entry && i<count) {
- if (FilterCmp(entry->area)) j++;
- entry = entry->next; i++;
- }
- arrowdown = (j < number-MAXLINE) ? 1 : 0;
- }
- if (arrowup) {
- SetAPen(RP,3L);
- RectFill(RP,11,101,14,107);
- Move(RP,8,104); Draw(RP,17,104); Draw(RP,13,100);
- Draw(RP,12,100); Draw(RP,9,103); Draw(RP,15,103);
- SetAPen(RP,1L);
- Move(RP,12,108); Draw(RP,15,108); Draw(RP,15,105);
- Draw(RP,18,105);
- }
- else {
- SetAPen(RP,0L);
- RectFill(RP,8,100,18,108);
- }
- if (arrowdown) {
- SetAPen(RP,3L);
- RectFill(RP,11,242,14,248);
- Move(RP,8,245); Draw(RP,17,245); Draw(RP,13,249);
- Draw(RP,12,249); Draw(RP,9,246); Draw(RP,15,246);
- SetAPen(RP,1L);
- Move(RP,15,243); Draw(RP,15,244);
- Move(RP,13,250); Draw(RP,17,246);
- Move(RP,14,250); Draw(RP,18,246);
- }
- else {
- SetAPen(RP,0L);
- RectFill(RP,8,242,18,250);
- }
- }
-
- void OutClr(void) /* clear screen */
- {
- SetAPen(RP,0L); RectFill(RP,8L,100L,635L,250L);
- }
-
- void Out(short first, short number, short offset) /* shows entries */
- {
- struct Entry *entry;
- short i, line;
- long costs;
- char s[100], date[7];
- date[2] = date[4] = '.'; date[5] = date[6] = 0;
- if (curmonth < 10) date[3] = curmonth + 48;
- else { date[3] = '1'; date[4] = curmonth + 38; date[5] = '.'; }
- i = first + offset;
- entry = year->month[curmonth].first;
- while (i && entry) { entry = entry->next; i--; }
- while (number && entry) {
- if (!filter || FilterCmp(entry->area)) {
- line = 10 * offset + 108;
- ltos(entry->date,s,2,0,' '); date[0] = s[0]; date[1] = s[1];
- if ((costs=entry->costs) > 0) SetAPen(RP,2L);
- else { costs = -costs; SetAPen(RP,1L); }
- ltos(costs,s,10,8,' '); Print(s,448-(modus*80),line);
- SetAPen(RP,1L);
- Print(date,40-(modus*8),line);
- if (!modus) Print(entry->title,112,line);
- else {
- strcpy(s,entry->title);
- if (strlen(s) > 33) {
- s[30] = s[31] = s[32] = '.'; s[33] = 0;
- }
- Print(s,96,line);
- Print(entry->area,472,line);
- }
- offset++; number--;
- }
- entry = entry->next;
- }
- Arrow();
- }
-
-
- void OutPrinter() /* print entries on printer*/
- {
- FILE *fp;
- struct Entry *entry;
- short prtnumber, filter2=filter;
- unsigned char daypos=0, i, s[100], date[11], t[20];
- StatusClr();
- ltos(curyear,date,10,0,' ');
- date[2] = date[3] = date[5] = '.';
- if (curmonth < 10) { daypos=1; date[4] = curmonth + 48; }
- else { date[3] = '1'; date[4] = curmonth + 38; }
- if (fp = fopen(prtname,"w")) {
- entry = year->month[curmonth].first;
- prtnumber = year->month[curmonth].number;
- ltos(prtnumber,t,4,0,' '); strcpy(s,"Noch "); strcat(s,t);
- strcat(s," Einträge zu drucken..."); StatusText(s,0,1);
- ltos(curyear,s,4,0,' ');
- fprintf(fp,"Bilanz %s %s",Monthname[curmonth],s);
- if (filter2) {
- fprintf(fp," für ");
- for (i=0;i<FILTER;i++) {
- if (filterflag[i]) {
- fprintf(fp,"%s",year->filtertext[i]);
- filter2 -= power2(i);
- if (filter2) fprintf(fp,", ");
- }
- }
- }
- fprintf(fp,"\n\n");
- ltos(yearincome,s,10,8,' '); ltos(yearexpend,t,10,8,' ');
- fprintf(fp,"Jahreseinnahmen: %s Jahresausgaben: %s\n",s,t);
- ltos(monthincome,s,10,8,' '); ltos(monthexpend,t,10,8,' ');
- fprintf(fp,"Monatseinnahmen: %s Monatsausgaben: %s\n\n",s,t);
- while (entry) {
- if (!filter || FilterCmp(entry->area)) {
- ltos(prtnumber--,t,4,0,' '); strcpy(s,"Noch "); strcat(s,t);
- StatusText(s,0,1);
- ltos(entry->date,s,2,0,' ');
- date[daypos] = s[0]; date[daypos+1] = s[1];
- ltos(entry->costs,s,10,8,' ');
- fprintf(fp,"%s %-40s %s %s\n",date,entry->title,s,entry->area);
- }
- entry = entry->next;
- }
- fclose(fp);
- StatusClr();
- }
- else {
- strcpy(s,"Kann "); strcat(s,prtname); strcat(s," nicht öffnen!");
- StatusText(s,1,2);
- }
- }
-
- void OutputDirection()
- { char change=changeflag;
- OutClr(); Frame(18,110,621,148,3);
- SetAPen(RP,1L); Print("Ausgabe auf ... (z.B. \"PRT:\" oder \"DF0:ausgabe\")",34,122);
- ReadText(prtname,34,140,70,1,INS, stopRead, 0,1,2,1);
- changeflag=change;
- }
-
-
- void ShowGadgets() /* draws gadgets (|<,<,>,>|) if necessary */
- { if (number <= MAXLINE) {
- if (entrygadgets) {
- entrygadgets = 0;
- Gadget(" ", 80,49,115,59,0);
- Gadget(" " ,120,49,155,59,0);
- Gadget(" " ,160,49,195,59,0);
- Gadget(" ",200,49,235,59,0);
- }
- }
- else if (entrygadgets<1) {
- entrygadgets = 1;
- Gadget("|<", 80,49,115,59,0);
- Gadget("<" ,120,49,155,59,0);
- Gadget(">" ,160,49,195,59,0);
- Gadget(">|",200,49,235,59,0);
- }
- }
-
- void OutStart() /* calculate costs and number of entries */
- {
- OutClr(); count = 0;
- if (!filter) {
- number = year->month[curmonth].number;
- monthincome = year->month[curmonth].income;
- monthexpend = year->month[curmonth].expend;
- }
- else {
- struct Entry *entry;
- int i=0;
- number = 0;
- monthincome = monthexpend = 0;
- entry = year->month[curmonth].first;
- while (entry) {
- if (FilterCmp(entry->area)) {
- if (!number) count = i; /* first filtered entry */
- number++;
- if (entry->costs > 0) monthincome += entry->costs;
- else monthexpend += labs(entry->costs);
- }
- entry = entry->next; i++;
- }
- }
- ShowGadgets();
- Out(count,MAXLINE,0);
- }
-
- void GetFilename(void) /* sets filename */
- { unsigned char s[5];
- strcpy(filename,PATH); strcat(filename,file);
- ltos(curyear,s,4,0,' '); strcat(filename,s);
- strcat(filename,".dat");
- }
-
- void Start() /* draws layout */
- {
- firstyear = 0;
- changeflag = modus = filter = counter = 0;
- include = 1;
- entrygadgets = -1;
- strcpy(prtname,PRTNAME);
- Gadget("<", 60,15, 90,25,0);
- Gadget(">",134,15,164,25,0);
- Gadget("<", 60,32, 90,42,0);
- Gadget(">",134,32,164,42,0);
- Gadget("Neu",240,49,289,59,0);
- Gadget("Monat drucken",360,49,480,59,0);
- Gadget("Voll",584,49,629,59,modus);
- Gadget("INCL",584,66,629,76,include);
- Frame(8,13,520,27,3); /* for year */
- Frame(8,30,520,44,3); /* for month */
- Frame(8,81,631,95,3); /* for status */
- SetAPen(RP,1L);
- Print("Jahr" ,16,23); Print("Ausgaben:",184,23); Print("Einnahmen:",352,23);
- Print("Monat",13,40); Print("Ausgaben:",184,40); Print("Einnahmen:",352,40);
- Print("Eintrag",12,57); Print("Ausgabe",516,57);
- Print("Filter",12,74);
- Print("Status:",12,91);
- curyear = time.year;
- curmonth = time.month;
- if (!InsertYear(&year)) {
- StatusText("Zu wenig Speicherplatz!\n",1,2);
- Delay(250);
- exit(1);
- }
- GetFilename();
- LoadData(filename);
- OutStart();
- StatusYear(0);
- }
-
- void YearChange(short step) /* step back/forward one year */
- { short ok;
- if (changeflag) { /* save changed data */
- SaveData(filename);
- StatusClr();
- changeflag = 0;
- }
- curyear += step;
- if ((ok = InsertYear(&year)) == 0) { /* mem for new year */
- StatusText("Nicht genug Speicherplatz frei!",1,2);
- curyear -= step;
- }
- else {
- GetFilename(); /* new year includes new filename */
- OutClr();
- if (ok == 1) LoadData(filename); /* load new data */
- else { /* data exists already */
- if (step==1) year = year->next;
- else {
- year = firstyear;
- while (year->year != curyear) year = year->next;
- }
- }
- OutStart();
- StatusYear(step);
- UpdateFilter(-1);
- }
- }
-
- void MonthBack()
- {
- if (--curmonth < 1) curmonth=12;
- OutStart();
- StatusMonth(-1);
- }
- void MonthNext()
- {
- if (++curmonth > 12) curmonth=1;
- OutStart();
- StatusMonth(1);
- }
-
- void EntryFirst()
- {
- if (Count(0)) {
- Gadget("|<",80,49,115,59,1);
- OutClr(); Out(count,MAXLINE,0);
- }
- Gadget("|<",80,49,115,59,0);
- }
- void EntryBack()
- { short i;
- while ((qualifier & 0x4000L || code==76) && Count(-1)) {
- Gadget("<",120,49,155,59,1);
- for(i=1; i<=10; i++) ScrollRaster(RP,0L,-1L,24L,100L,635L,250L);
- Out(count,1,0);
- GetMessageClass();
- }
- Gadget("<",120,49,155,59,0);
- }
- void EntryNext()
- { short i;
- while ((qualifier & 0x4000L || code==77) && Count(1)) {
- Gadget(">",160,49,195,59,1);
- for(i=1; i<=10; i++) ScrollRaster(RP,0L,1L,24L,100L,635L,250L);
- Out(count,1,(short)(MAXLINE-1));
- GetMessageClass(); GetMessageClass();
- }
- Gadget(">",160,49,195,59,0);
- }
- void EntryLast()
- {
- if (Count(2)) {
- Gadget(">|",200,49,235,59,1);
- OutClr(); Out(count,MAXLINE,0);
- }
- Gadget(">|",200,49,235,59,0);
- }
-
-
- void EntryInput(struct Entry *entry, int modus)
- { /* modus = 0 -> new entry
- modus = 1 -> change or delete entry */
- unsigned char s[200], abbruch=0, w, deleted = 0,
- stopRead[] = {13,1,4,5,0}, stopDate[] = {13,1,2,4,5,0};
- int x, y, line=1, flag=0;
- float costs;
- if (modus) {
- SetAPen(RP,1L);
- Print("Eintrag löschen",470,200);
- Frame(440,185,620,209,3);
- }
- else {
- entry->date = time.day;
- entry->area[0] = entry->title[0] = 0;
- entry->costs = 0;
- }
- SetAPen(RP,1L);
- Print("Datum : .",64,140);
- Print(Monthname[curmonth],168,140);
- ltos(curyear,s,4,0,' '); Print(s,200,140);
- Print("Titel :",64,150); Print(entry->title,136,150);
- Print("Bereich:",64,160); Print(entry->area,136,160);
- Print("Betrag :",64,170); ltos(entry->costs,s,10,8,' '); Print(s,136,170);
- Print("Ok",310,200); Frame(280,185,356,209,3);
- if (entry->costs > 0) {
- year->month[curmonth].income -= entry->costs;
- year->income -= entry->costs;
- if (!filter || FilterCmp(entry->area)) monthincome -= entry->costs;
- }
- else {
- year->month[curmonth].expend += entry->costs;
- year->expend += entry->costs;
- if (!filter || FilterCmp(entry->area)) monthexpend += entry->costs;
- }
- do {
- switch (line) {
- case 1: ltos(entry->date,s,2,0,' ');
- w = ReadText(s,136,140,2,1,OVR,stopDate,0,1,2,1);
- entry->date = atol(s);
- if (entry->date < 0 || entry->date > 31) entry->date = 0;
- ltos(entry->date,s,2,0,' '); Print(s,136,140);
- line = (w==65) ? 5 : 2;
- break;
- case 2: w = ReadText(entry->title,136,150,40,1,INS,stopRead,0,1,2,1);
- line = (w==65) ? 1 : 3;
- break;
- case 3: w = ReadText(entry->area,136,160,20,1,INS,stopRead,0,1,2,1);
- line = (w==65) ? 2 : 4;
- break;
- case 4: if (entry->costs==0) strcpy(s,"0 ");
- else ltos(entry->costs,s,10,8,' ');
- w = ReadText(s,136,170,10,1,OVR,stopRead,0,1,2,1);
- costs = round(stof(s) * 100.0);
- if (costs <= -1e8 || costs >= 1e8) {
- StatusText("Betrag muß > -1 Millionen und < +1 Millionen sein",0,2);
- costs = 0.0;
- }
- entry->costs = costs;
- ltos(entry->costs,s,10,8,' '); Print(s,136,170);
- line = (w==65) ? 3 : 5;
- break;
- case 5: strcpy(s,"Ok");
- w = ReadText(s,310,200,2,1,INS,stopRead,2,1,2,1);
- Print("Ok",310,200);
- if (w==13) abbruch=1;
- line = (w==65) ? 4 : 1;
- }
- if (w>=48 && w<=57) {
- w-=48;
- strcpy(entry->area,year->filtertext[w]);
- SetAPen(RP,0L); RectFill(RP,136L,152L,300L,161L);
- SetAPen(RP,1L); Print(entry->area,136,160);
- changeflag = 1; line = 4;
- }
- else if (w==1) {
- x = win->MouseX; y = win->MouseY;
- if (y > 64 && y < 78) {
- flag = (x - 64)/74;
- if (flag>=0 && flag<FILTER) {
- FilterSwitch(flag);
- flag++;
- }
- }
- do {
- GetMessageClass();
- } while (qualifier & 0x4000L);
- x = win->MouseX; y = win->MouseY;
- if (flag) {
- strcpy(entry->area,year->filtertext[--flag]);
- SetAPen(RP,0L); RectFill(RP,136L,152L,300L,161L);
- SetAPen(RP,1L); Print(entry->area,136,160);
- changeflag = 1; line = 4;
- FilterSwitch(flag);
- flag = 0;
- }
- else if (y>=185 && y<=209) {
- if (x>=280 && x<=356) abbruch = 1;
- else if (x>=440) {
- DeleteEntry(entry);
- changeflag = 1; deleted = abbruch = 1;
- }
- else line = 5;
- }
- else {
- line = (y - 122) / 10;
- if (line < 1) line = 1;
- else if (line > 4) line = 5;
- }
- }
- } while (!abbruch);
- if (deleted) {
- year->month[curmonth].number--;
- if (!filter || FilterCmp(entry->area)) number--;
- Count(-1);
- }
- else if (entry->costs > 0) {
- year->month[curmonth].income += entry->costs;
- year->income += entry->costs;
- if (!filter || FilterCmp(entry->area)) monthincome += entry->costs;
- }
- else {
- year->month[curmonth].expend -= entry->costs;
- year->expend -= entry->costs;
- if (!filter || FilterCmp(entry->area)) monthexpend -= entry->costs;
- }
- }
-
-
- void EntryNew()
- { struct Entry entry;
- int change = changeflag;
- OutClr();
- SetAPen(RP,1L); Print("Neuer Eintrag: ",50,120);
- changeflag = 0;
- EntryInput(&entry,0);
- if (changeflag) {
- if (InsertEntry(entry,curmonth)) {
- year->month[curmonth].number++;
- if (!filter || FilterCmp(entry.area)) number++;
- StatusYear(1);
- ShowGadgets();
- Count(2);
- }
- else StatusText("Nicht genug Speicherplatz!",0,2);
- }
- else changeflag = change;
- OutClr(); Out(count,MAXLINE,0);
- }
-
- void EntryChange(int nr)
- { struct Entry *entry;
- int i;
- OutClr();
- SetAPen(RP,1L); Print("Eintrag ändern:",50,120);
- entry = year->month[curmonth].first;
- for (i=0; i<count; i++) entry = entry->next;
- i = 0;
- while (i < nr) {
- entry = entry->next;
- if (!filter) i++;
- else if (FilterCmp(entry->area)) i++;
- }
- EntryInput(entry,1);
- StatusYear(1);
- ShowGadgets();
- OutClr(); Out(count,MAXLINE,0);
- }
-